| Conditions | 8 |
| Paths | 41 |
| Total Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | import process from 'child_process' |
||
| 17 | var abeProcess = function(name, args = []) { |
||
| 18 | args = prepend(`ABE_WEBSITE=${config.root}`, args) |
||
| 19 | args = prepend(`ABEJS_PATH=${__dirname}/../../../dist`, args) |
||
| 20 | |||
| 21 | if (!abeExtend.lock.create(name)) { |
||
| 22 | return false |
||
| 23 | } |
||
| 24 | |||
| 25 | var proc |
||
| 26 | var file = `${__dirname}/../../cli/process/${name}.js` |
||
| 27 | try { |
||
| 28 | var stats = fse.statSync(file) |
||
| 29 | if (stats.isFile()) { |
||
| 30 | proc = process.fork(file, args) |
||
| 31 | } |
||
| 32 | }catch(err) { |
||
| 33 | try { |
||
| 34 | file = abeExtend.plugins.instance.getProcess(name) |
||
| 35 | stats = fse.statSync(file) |
||
| 36 | if (stats.isFile()) { |
||
| 37 | proc = process.fork(file, args) |
||
| 38 | } |
||
| 39 | }catch(err) { |
||
| 40 | console.log('process fork failed') |
||
|
|
|||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | if(typeof proc !== 'undefined' && proc !== null) { |
||
| 45 | proc.on('message', function( msg ) { |
||
| 46 | abeExtend.lock.remove(name) |
||
| 47 | proc.kill() |
||
| 48 | }); |
||
| 49 | return true |
||
| 50 | } |
||
| 51 | |||
| 52 | return false |
||
| 53 | } |
||
| 54 | |||
| 55 | export default abeProcess |